﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DBSourceToolsLib;
using System.Configuration;
using System.Collections;
using DBSourceToolsLib.Interfaces;
using ITDM;
using StructureMap;
using StructureMap.Diagnostics.TreeView;


namespace DBSourceTools
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            
            bool bConfigLoaded = false;
            bool bIsCommandLine = false;
            int returnCode = 0;
            try
            {

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                ObjectFactory.Initialize(x => x.AddRegistry(new DbSourceToolsRegistry()));
                UserSettings.Instance().StartupPath = Application.StartupPath;
                if (args.Length > 0)
                {
                    // check to see if this file is a project file.
                    if (System.IO.File.Exists(args[0]))
                    {
                        if (args[0].EndsWith(".dbsp"))
                        {
                            UserSettings.Instance().LoadLastProjectConfigFile(args[0]);
                            bConfigLoaded = true;
                        }
                    }
                }

                if (!bConfigLoaded)
                    UserSettings.Instance().LoadAppConfig();

            }
            catch (Exception ex)
            {

                DBSourceToolsLib.SysObjects.UI.Forms.ErrorForm oError =
                    new DBSourceToolsLib.SysObjects.UI.Forms.ErrorForm(ex.ToString());
                oError.ShowDialog();

            }


            Application.Run(new MainForm());

            try
            {
                UserSettings.Instance().SaveRecentFileList();
            }
            catch (Exception ex)
            {
                DBSourceToolsLib.SysObjects.UI.Forms.ErrorForm oError =
                    new DBSourceToolsLib.SysObjects.UI.Forms.ErrorForm(ex.ToString());
                oError.Show();

            }

        }


    }
}

